import Moveable from './moveable.js'
import config from './gameconfig.js'
import Block from './block.js'
import Bullet from './bullet.js'

class Tank extends Moveable {
  imageList: Array<string>
  attack: number = config.TankBaseAttack
  shootReady: boolean = true
  shootInterval: number = 500
  constructor(
    x: number,
    y: number,
    imgSrc?: string,
    width?: number,
    height?: number,
    life?: number,
  ) {
    super(x, y, imgSrc, width, height, life)
    this.imageList = config.PlayerSprites
  }
  chageImage(): void {
    this.img.src = this.imageList[this.direction]
  }
  controlMove(col: Array<Block>): boolean {
    this.chageImage()
    return this.move(col)
  }
  shoot(): Bullet | boolean {
    if (this.shootReady) {
      this.shootReady = false;
      setTimeout(() => {
        this.shootReady = true;
      }, this.shootInterval);
      let x = this.x + this.width / 2 - config.BulletSize / 2
      let y = this.y + this.height / 2 - config.BulletSize / 2
      let bullet = new Bullet(x, y);
      return bullet
    } else {
      return false
    }
  }
}
export default Tank
